//
//  BanBu_Remind.m
// Halfarea
//
//  Created by banbu3 on 14-6-23.
//
//

#import "BanBu_Remind.h"
#import "UIAlertView+XY.h"
#import "AppDataManager.h"
#import "BanBu_ChangePWViewController.h"
#import "LeveyTabBarController.h"
@implementation BanBu_Remind


+ (BOOL)shouldPrompt
{
    //修改，只有新注册用户显示修改密码提示2014/07/11
    if([[UserDefaults valueForKey:@"isDefaultKey"] boolValue])
    {
        return YES;
    }
    else
    {
        return NO;
    }

//    if(![UserDefaults valueForKey:@"isDefaultKey"])
//    {
//        return NO;
//    }
//    NSDateFormatter * formatter = [[[NSDateFormatter alloc]init] autorelease];
//    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    if(!MyAppDataManager.useruid&&!MyAppDataManager.useruid.length)
//    {
//        return NO;
//    }
//    NSString *timeSting = [UserDefaults valueForKey:[NSString stringWithFormat:@"registertime%@",MyAppDataManager.useruid]];
//
//    NSDate  *regDate = [NSDate date];
//    if(timeSting)
//    {
//        regDate = [formatter dateFromString:timeSting];
//    }
//    else
//    {
//        [UserDefaults setValue:[formatter stringFromDate:[NSDate date]] forKey:[NSString stringWithFormat:@"registertime%@",MyAppDataManager.useruid]];
//    }
//    NSTimeInterval timeI = -[regDate timeIntervalSinceNow];
//    
//    if(timeI > 3600*24)
//    {
//        return YES;
//    }
//    return NO;
}
#pragma mark - 修改密码提示
+ (void)modifyPasswordPromptTitle:(NSString *)title Detail:(NSString *)detail Type:(RemindType)type goBlock:(void (^)())completeBlock cancelBlock:(void (^)())cancelBlock
{
    if(![BanBu_Remind shouldPrompt])
    {
        return;
    }
    UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:title message:detail delegate:nil cancelButtonTitle:NSLocalizedString(@"cancelNotice", nil) otherButtonTitles:NSLocalizedString(@"confirmNotice", nil), nil,nil] autorelease];
    
    [alertView handlerClickedButton:^(UIAlertView *alertView, NSInteger btnIndex)
    {
        if(btnIndex == 1)
        {
            
            if(completeBlock)
            {
                completeBlock();
            }
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:@"registertime"]];
            [dic setValue:[NSString stringWithFormat:@"%@",[NSDate date]] forKey:@"registertime"];
            [UserDefaults setValue:dic forKey:@"registertime"];
            BanBu_AppDelegate *ap = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
            LeveyTabBarController *lef = ap.tabbarController;
            
            UINavigationController *nav = [lef.viewControllers objectAtIndex:lef.selectedIndex];
            BanBu_ChangePWViewController *change = [[BanBu_ChangePWViewController alloc] init];
            [lef hidesTabBar:YES animated:YES];
            [nav pushViewController:change animated:YES];
            [change release];
            
        }
        else
        {
            
        }
       
        
    }];

    [alertView show];
}


@end
